//
//  FactoryTestCase.m
//  CocoaSynth
//
//  Created by Simon André on 23/02/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "FactoryTestCase.h"
#import <SenTestingKit/SenTestingKit.h>
#import "Module.h"
#import "ModuleViewController.h"
#import "Factory.h"
#import "PortOut.h"

#import "ModuleVCOProtocol.h"
#import "ModuleVCFProtocol.h"
#import "ModuleVCAProtocol.h"
#import "ModuleADSRProtocol.h"
#import "ModuleDispatcher.h"


@implementation FactoryTestCase

-(void) testCreateVCO{
	ModuleViewController* vco = [Factory createVCO];
	STAssertNotNil(vco,@"vco controller not initianalised");
	STAssertNotNil([vco model],@"vco controller is not connected to a model");
	Module<ModuleVCOProtocol>* module = [vco model];
	//STAssertTrue([module exponentialFrequency]== ,@"incorect initianalisation of exponentialFrequency");
	STAssertNotNil([module portIn],@"the created VCO has no port IN");
	NSArray* portsOutList = [module portsOut];
	for (id<PortOutProtocol> port in portsOutList) {
		STAssertEquals([port module],module,@"a port out of the created VCO is not conected to it's model");
	}
}

-(void) testCreateVCF{
	ModuleViewController* vcf = [Factory createVCF];
	STAssertNotNil(vcf,@"vcf controller not initianalised");
	STAssertNotNil([vcf model],@"vcf controller is not connected to a model");
	Module<ModuleVCFProtocol>* module = [vcf model];
	STAssertNotNil([module portIn],@"created vcf has no port in");
	STAssertNotNil([module cutOffFrequencyPort],@"created vcf has no port for cutoff frequency");	
	STAssertTrue([[module portsOut] count]==1, @"VCF should have exactly one port out");
	STAssertEquals([[[[module portsOut] objectEnumerator] nextObject] module],module , @"the port out of the created vcf should have the vcf as module");
}

-(void) testCreateVCA{
	ModuleViewController* vca = [Factory createVCA];
	STAssertNotNil(vca,@"vca controller not initianalised");
	STAssertNotNil([vca model],@"vca controller is not connected to a model");
	Module<ModuleVCAProtocol>* module = [vca model];
	STAssertNotNil([module portIn],@"created vca has no port in");
	STAssertNotNil([module portInAm],@"created vca has no port in am");
	STAssertNotNil([module portsOut],@"created vca has no ports out");
	STAssertTrue([[module portsOut] count]>0,@"created vca has no ports out");
	NSArray* portsOutList = [module portsOut];
	for (id<PortOutProtocol> port in portsOutList) {
		STAssertEquals([port module],module,@"a port out of the created vca is not conected to it's model");
	}
}

-(void) testCreateADSR{
	ModuleViewController* adsr = [Factory createADSR];
	STAssertNotNil(adsr,@"adsr controller not initianalised");
	STAssertNotNil([adsr model],@"adsr controller is not connected to a model");
	Module<ModuleADSRProtocol>* module = [adsr model];
	STAssertNotNil([module portIn],@"created adsr has no port in");
	STAssertNotNil([module portsOut],@"created adsr has no ports out");
	STAssertTrue([[module portsOut] count]>0,@"created adsr has no ports out");
	NSArray* portsOutList = [module portsOut];
	for (id<PortOutProtocol> port in portsOutList) {
		STAssertEquals([port module],module,@"a port out of the created adsr is not conected to it's model");
	}
	
}

-(void) testCreateSpeaker{
	ModuleViewController* speaker = [Factory createSpeaker];
	STAssertNotNil(speaker, @"speaker controller not initianalised");
	STAssertNotNil([speaker model], @"speaker controller not connected to a model");
	STAssertNotNil([[speaker model] portIn], @"speaker has no port in");
}

-(void) testCreateWriter{
	ModuleViewController* writer = [Factory createWriter];
	STAssertNotNil(writer, @"writer controller not initianalised");
	STAssertNotNil([writer model], @"writer controller not connected to a model");
	STAssertNotNil([[writer model] portIn], @"writer has no port in");
}

-(void) testCreatekeyboard{
	ModuleViewController* keyboard = [Factory createKeyboard];
	STAssertNotNil(keyboard, @"keyboard controller not initianalised");
	STAssertNotNil([keyboard model], @"keyboard controller not connected to a model");
	STAssertNotNil([[keyboard model] portsOut], @"keyboard has no port out");
	STAssertTrue([[[keyboard model] portsOut] count]==1, @"keyboard should have exactly one port out");
	STAssertEquals([[[[[keyboard model] portsOut] objectEnumerator] nextObject] module],[keyboard model] , @"the port out of the keyboard should have the keyboard as module");
}

-(void) testCreateDispacher{
	ModuleViewController* dispacher = [Factory createDispatcher];
	STAssertNotNil(dispacher,@"dispacher controller not initianalised");
	STAssertNotNil([dispacher model],@"dispacher controller is not connected to a model");
	Module* module = [dispacher model];
	STAssertNotNil([module portIn],@"created dispacher has no port in");
	STAssertNotNil([module portsOut],@"created dispacher has no ports out");
	STAssertTrue([[module portsOut] count]>0,@"created dispacher has no ports out");
	NSArray* portsOutList = [module portsOut];
	for (id<PortOutProtocol> port in portsOutList) {
		STAssertEquals([port module],module,@"a port out of the created dispacher is not conected to it's model");
	}
}

-(void) testCreateConnector{
	id<ConnectorProtocol> connector = [Factory createConnector];
	STAssertNotNil(connector,@"connector not initianalised");
}
@end
